var express = require('express')
var router = express.Router()

var { getUsers, getUsersById, addUsers, updateUsers, deleteUsers } = require('../controller/users')


/**
 * @api {get} /users 1.1 获取用户信息
 * @apiName GetUser
 * @apiGroup User
 *
 * @apiParam {null} null null
 * @apiParam {String} token 必填
 *
 * @apiSuccessExample {json} Success-Response:
{
  "status": 0,
  "message": [
    {
    "id": 1,
    "name": "小安妮",
    "age": 44,
    "ctime": "2020-01-16 16:00:54",
    "isdel": 1
    },
    {
    "id": 2,
    "name": "spssssss",
    "age": 666,
    "ctime": "2020-01-17 10:49:51",
    "isdel": 0
    },
    {
    "id": 3,
    "name": "sy",
    "age": 999,
    "ctime": "2020-01-16 11:47:34",
    "isdel": 1
    }
  ]
}
 */
router.get('/users', getUsers)


/**
 * @api {get} /users/:id 1.2 根据id获取用户信息
 * @apiName GetUserById
 * @apiGroup User
 *
 * @apiParam {Number} id 必填
 * @apiParam {String} token 必填
 *
 * @apiSuccessExample {json} Success-Response:
{
  "status": 0,
  "message": [
    {
    "id": 1,
    "name": "小安妮",
    "age": 44,
    "ctime": "2020-01-16 16:00:54",
    "isdel": 1
    }
  ]
}
 */
router.get('/users/:id', getUsersById)

/**
 * @api {post} /users 1.3 添加用户信息
 * @apiName addUser
 * @apiGroup User
 *
 * @apiParam {String} name 必填
 * @apiParam {Number} age 必填
 * @apiParam {String} token 必填
 *
 * @apiSuccessExample {json} Success-Response:
{
  "status": 0,
  "message": "添加用户成功"
}
 */
router.post('/users', addUsers)

/**
 * @api {put} /users/:id 1.4 根据id更新用户信息
 * @apiName updateUsers
 * @apiGroup User
 *
 * @apiParam {Number} id 必填
 * @apiParam {String} name 必填
 * @apiParam {Number} age 必填
 * @apiParam {String} token 必填
 *
 * @apiSuccessExample {json} Success-Response:
{
  "status": 0,
  "message": "更新成功"
}
 */
router.put('/users/:id', updateUsers)

/**
 * @api {delete} /users/:id 1.5 根据id删除用户信息
 * @apiName deleteUser
 * @apiGroup User
 * @apiParam {String} token 必填
 *
 * @apiParam {Number} id 必填
 *
 * @apiSuccessExample {json} Success-Response:
{
  "status": 0,
  "message": "删除成功"
}
 */
router.delete('/users/:id', deleteUsers)

module.exports = router
